import 'package:flutter/material.dart';
import 'package:flutter_demo/chapter8-EventNotification/event-mechanism/HitTestBlocker.dart';
import 'package:flutter_demo/chapter8-EventNotification/gesture-conflict/CustomTapGestureRecongnizer.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Notification Widget Demo"),
      ),
      body: CustomNotificationWidget(),
    ),
  ));
}

class CustomNotificationWidget extends StatefulWidget {
  @override
  _CustomNotificationWidgetState createState() =>
      _CustomNotificationWidgetState();
}

class _CustomNotificationWidgetState extends State<CustomNotificationWidget> {
  String _msg = '';

  @override
  Widget build(BuildContext context) {
    return NotificationListener<MyNotification>(
      onNotification: (notification) {
        print(notification.msg);
        return false;
      },
      child: NotificationListener<MyNotification>(
        onNotification: (notification){
          //  终止通知冒泡
          // return true;
          return false;
        },
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Builder(builder: (context) {
              return ElevatedButton(
                onPressed: () => MyNotification('HI').dispatch(context),
                child: const Text('Send Notification2'),
              );
            }),
            Text(_msg),
          ],
        ),

      ),
    );
  }
}

class MyNotification extends Notification {
  MyNotification(this.msg);

  final String msg;
}
